package us.mooresr.geartrack.server.handler;

import java.util.ArrayList;

import us.mooresr.geartrack.server.DAO;
import us.mooresr.geartrack.shared.action.GetAllLoansAction;
import us.mooresr.geartrack.shared.action.GetAllLoansResult;
import us.mooresr.geartrack.shared.model.Loan;

import com.googlecode.objectify.Query;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class GetAllLoansActionHandler implements ActionHandler<GetAllLoansAction, GetAllLoansResult>{

	@Override
	public GetAllLoansResult execute(GetAllLoansAction arg0,
			ExecutionContext arg1) throws ActionException {
		DAO dao = new DAO();
		

		
		ArrayList<Loan> loanList = new ArrayList<Loan>();
		
		Query<Loan> q = dao.ofy().query(Loan.class);
		
		for (Loan r : q) {
			loanList.add(r);
		}
		
		return new GetAllLoansResult(loanList);
	}

	@Override
	public Class<GetAllLoansAction> getActionType() {
		return GetAllLoansAction.class;
	}

	@Override
	public void undo(GetAllLoansAction arg0, GetAllLoansResult arg1,
			ExecutionContext arg2) throws ActionException {
		// TODO Auto-generated method stub
		
	}

}
